// Memory data postprocessor
module dat_postproc(
	input		i_part,
	input		i_half,
	input		i_sign_ext,
	input	[1:0]	i_byte_index,
	input	[31:0]	i_data,
	output	[31:0]	o_result
);

reg	[31:0]	word;

always @* begin
	case (i_byte_index)
		2'b00: word =                i_data        ;
		2'b01: word = {i_data[ 7:0], i_data[31: 8]};
		2'b10: word = {i_data[15:0], i_data[31:16]};
		2'b11: word = {i_data[23:0], i_data[31:24]};
	endcase
end

wire	[31:0]	byte_ext = {{24{i_sign_ext & word[ 7]}}, word[ 7:0]};
wire	[31:0]	half_ext = {{16{i_sign_ext & word[15]}}, word[15:0]};

assign  o_result = i_part ? (i_half ? half_ext : byte_ext) : word;

endmodule
